package com.bawei.es.controller;

import com.bawei.common.core.domain.R;
import com.bawei.domain.request.IndexInfoReq;
import com.bawei.domain.response.IndexInfoResp;
import com.bawei.es.service.EsIndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/es/index")
public class EsIndexController {
    @Autowired
    private EsIndexService esIndexService;

    @PostMapping("/createIndex")
    public R createIndex(@RequestBody IndexInfoReq indexInfoReq){
        esIndexService.createIndex(indexInfoReq);
        return R.ok();
    }


    @GetMapping("/deleteIndex")
    public  R deleteIndex(@RequestParam String indexName){
        esIndexService.deleteIndex(indexName);
        return R.ok();
    }

    @GetMapping("/isExits")
    public  R isExits(@RequestParam String indexName){
        boolean exits = esIndexService.isExits(indexName);
        return R.ok();
    }


    @PostMapping("/modifyIndex")
    public  R modifyIndex(@RequestParam String newIndexName,@RequestBody IndexInfoReq indexInfoReq){
        esIndexService.modifyIndex(newIndexName,indexInfoReq);
        return R.ok();
    }


    @PostMapping("/getIndex")
    public  R getIndex(@RequestParam String indexName){
        IndexInfoResp index = esIndexService.getIndex(indexName);
        return R.ok(index);
    }



}
